{% extends "base.html" %}
{% block header %}系统参数管理{% endblock %}
{% block content %}
<div class="container">
    <a href="{% url 'system_config_create' %}" class="btn btn-success mb-3">添加参数</a>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>参数名</th>
                <th>类型</th>
                <th>选项</th>
                <th>参数值</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
        {% for config in page_obj %}
            <tr>
                <td>{{ config.id }}</td>
                <td>{{ config.name }}</td>
                <td>{{ config.key }}</td>
                <td>{{ config.get_type_display }}</td>
                <td>{{ config.options }}</td>
                <td>{{ config.value }}</td>
                <td>{{ config.remark }}</td>
                <td>
                    <a href="{% url 'system_config_edit' config.id %}" class="btn btn-sm btn-primary">编辑</a>
                    <form method="post" action="{% url 'system_config_delete' config.id %}" style="display:inline;">
                        {% csrf_token %}
                        <button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('确定删除？');">删除</button>
                    </form>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    <!-- 分页控件 -->
    <nav aria-label="Page navigation">
      <ul class="pagination">
        {% if page_obj.number > 1 %}
          <li class="page-item"><a class="page-link" href="?page=1">首页</a></li>
        {% endif %}
        {% if page_obj.has_previous %}
          <li class="page-item"><a class="page-link" href="?page={{ page_obj.previous_page_number }}">上一页</a></li>
        {% endif %}
        {% for num in page_obj.paginator.page_range %}
          {% if page_obj.number == num %}
            <li class="page-item active"><span class="page-link">{{ num }}</span></li>
          {% else %}
            <li class="page-item"><a class="page-link" href="?page={{ num }}">{{ num }}</a></li>
          {% endif %}
        {% endfor %}
        {% if page_obj.has_next %}
          <li class="page-item"><a class="page-link" href="?page={{ page_obj.next_page_number }}">下一页</a></li>
        {% endif %}
        {% if page_obj.number < page_obj.paginator.num_pages %}
          <li class="page-item"><a class="page-link" href="?page={{ page_obj.paginator.num_pages }}">尾页</a></li>
        {% endif %}
      </ul>
    </nav>
</div>
{% endblock %}
